﻿using Microsoft.Extensions.Logging;
using NuGet.Protocol.Core.Types;
using QuickGet.Core.Models;
using QuickGet.Core.Services;

namespace QuickGet.Core
{
    public abstract class NugetOperationBase
    {
        protected virtual ILogger _logger { get; set; }

        protected virtual NuGet.Common.ILogger _nugetLogger { get; set; }
        protected virtual SourceCacheContext _sourceCache { get; set; }

        protected virtual INugetResourceResolver _resourceResolver { get; set; }
        protected virtual INugetSourceRepositoryResolver _sourceRepositoryResolver { get; set; }

        public NugetOperationBase(
            ILogger logger,
            SourceCacheContext sourceCache,
            INugetResourceResolver nugetResourceResolver,
            INugetSourceRepositoryResolver nugetSourceRepositoryResolver)
        {
            _logger = logger;
            _nugetLogger = new NugetLogger(logger);

            _resourceResolver = nugetResourceResolver;
            _sourceRepositoryResolver = nugetSourceRepositoryResolver;

            _sourceCache = sourceCache;
        }

        protected virtual async Task<FindPackageByIdResource?> GetFindPackageByIdResourceAsync(string packageSourceName, CancellationToken cancellationToken)
        {
            return await _resourceResolver.GetResourceAsync<FindPackageByIdResource>(packageSourceName, cancellationToken);
        }
    }
}
